import { http } from "@/utils/http";

/** 告警日志模型定义 */
export type AlertLogModel = {
  id: number;
  sceneId: number;
  level: number;
  bindTo: number;
  bindId: string;
  deptId: number;
  handleStatus: number;
  handRemark?: string;
  createTime?: string;
  // 可能的其他字段
  [key: string]: any;
};

/** 分页获取告警日志列表 */
export const getAlertLogPageListApi = (data: IReqPagerData) => {
  return http.request<Resp<IRespPagerData<AlertLogModel>>>(
    "get",
    "/alert-log/page-list",
    { params: data }
  );
};

/** 新增告警日志 */
export const addAlertLogApi = (data: Partial<AlertLogModel>) => {
  return http.request<Resp<null>>("post", "/alert-log", { data });
};

/** 更新告警日志 */
export const updateAlertLogApi = (id: number, data: Partial<AlertLogModel>) => {
  return http.request<Resp<null>>("put", `/alert-log/${id}`, { data });
};

/** 更新告警日志状态 */
export const updateAlertLogStatusApi = (id: number, handleStatus: number) => {
  return http.request<Resp<null>>("patch", `/alert-log/${id}/status`, {
    data: { handleStatus }
  });
};

/** 删除告警日志 */
export const deleteAlertLogApi = (id: number) => {
  return http.request<Resp<null>>("delete", `/alert-log/${id}`);
};

/** 根据ID获取告警日志详情 */
export const getAlertLogByIdApi = (id: number) => {
  return http.request<Resp<{
    info: AlertLogModel
  }>>("get", "/alert-log/getOne", {
    params: { id }
  });
};

/** 获取告警日志选项 */
export const getAlertLogOptionsApi = (params?: { fieldKey?: string; fieldLabel?: string }) => {
  return http.request<Resp<{
    options: Array<{
      label: string;
      val: string | number;
    }>
  }>>("get", "/alert-log/getOptions", { params });
};

/** 处理告警日志 */
export const handleAlertLogApi = (id: number, handleStatus: number, handRemark?: string) => {
  return http.request<Resp<null>>("post", "/alert-log/handle", {
    data: { id, handleStatus, handRemark }
  });
};

/** 批量删除告警日志 */
export const batchDeleteAlertLogApi = (ids: number[]) => {
  return http.request<Resp<null>>("delete", "/alert-log/batch-del", {
    data: { ids }
  });
};

/** 批量处理告警日志 */
export const batchHandleAlertLogApi = (ids: number[], handleStatus: number, handRemark?: string) => {
  return http.request<Resp<null>>("post", "/alert-log/batch-handle", {
    data: { ids, handleStatus, handRemark }
  });
};